package com.mini.rpc.provider;

import com.mini.rpc.core.RpcProperties;
import com.mini.rpc.register.RegistryFactory;
import com.mini.rpc.register.RegistryService;
import com.mini.rpc.register.RegistryType;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author lbx
 * @version 1.0.0
 * @description TODO
 * @date 2021/10/5 9:47
 **/
@Configuration
@EnableConfigurationProperties(RpcProperties.class)
public class RpcProviderAutoConfiguration {

    @Resource
    private RpcProperties rpcProperties;


    @Bean
    public RpcProvider init() throws Exception {
        RegistryType registryType = RegistryType.valueOf(rpcProperties.getRegistryType());
        RegistryService registryService = RegistryFactory.getInstance(rpcProperties.getRegistryAddr(), registryType);
        return new RpcProvider(rpcProperties.getServicePort(), registryService);
    }

}
